from poker_bot.core.models.dto.deposit import DepositDTO, DepositWithDetailsDTO
from poker_bot.database.models import Deposit
from poker_bot.domain.deposit import DepositEntity


def convert_db_model_to_deposit_with_details_dto(
    deposit: Deposit, with_currency: bool = False
):
    currency_symbol = ""
    if with_currency and deposit.payment_method:
        currency_symbol = deposit.payment_method.currency_symbol.value

    return DepositWithDetailsDTO(
        id=deposit.id,
        status=deposit.status,
        summ=deposit.summ,
        user_id=deposit.user_id,
        payment_method_id=deposit.payment_method_id,
        currency_symbol=currency_symbol,
        invoice_screenshot_path=deposit.invoice_screenshot_path,
        created_at=deposit.created_at,
    )


def convert_db_model_to_deposit_dto(
    deposit: Deposit,
) -> DepositDTO:
    return DepositDTO(
        id=deposit.id,
        status=deposit.status,
        summ=deposit.summ,
        user_id=deposit.user_id,
        payment_method_id=deposit.payment_method_id,
        invoice_screenshot_path=deposit.invoice_screenshot_path,
        created_at=deposit.created_at,
    )


def convert_db_model_to_deposit_entity(deposit: Deposit) -> DepositEntity:
    return DepositEntity(
        id=deposit.id,
        status=deposit.status,
        account_id=deposit.account_id,
        summ=deposit.summ,
        buyer_db_id=deposit.user_id,
        payment_method_id=deposit.payment_method_id,
        invoice_screenshot_path=deposit.invoice_screenshot_path,
    )


def convert_deposit_entity_to_db_model(deposit: DepositEntity) -> Deposit:
    return Deposit(
        id=deposit.id,
        status=deposit.status,
        account_id=deposit.account_id,
        summ=deposit.summ,
        user_id=deposit.buyer_db_id,
        payment_method_id=deposit.payment_method_id,
        invoice_screenshot_path=deposit.invoice_screenshot_path,
    )
